﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Common.OA.WorkOvertimeRecord;
using BCService.CommonService.OA.WorkOvertimeRecord;
using BlackCoffeeRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BlackCoffeeRESTful.Controllers.Management.OA
{
    /// <summary>
    /// 加班记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkOvertimeRecoreController : ManagementBaseController
    {
        private readonly IWorkOvertimeRecordService workOvertimeRecordService;

        public WorkOvertimeRecoreController(IWorkOvertimeRecordService workOvertimeRecordService)
        {
            this.workOvertimeRecordService = workOvertimeRecordService;
        }

        #region 创建一条加班信息
        /// <summary>
        /// 创建一条加班信息
        /// </summary>
        /// <param name="dto">加班信息</param>
        /// <response code="200">新创建的加班信息</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建一条加班信息")]
        [ProducesResponseType(typeof(WorkOvertimeRecordDto), 200)]

        public IActionResult Post([FromBody] WorkOvertimeRecordRequestDto dto)
        {

            return Ok(this.workOvertimeRecordService.Create(dto,this.Admin));
        }
        #endregion

        #region 修改一条加班信息

        /// <summary>
        /// 修改加班信息
        /// </summary>
        /// <param name="workOverTimeRecordNo">加班信息ID</param>
        /// <param name="dto">修改的加班信息模型</param>    
        /// <returns></returns>
        /// <response code="200">修改后的加班信息。</response>
        [HttpPut("{work_overtime_record_no}")]
        [Log("修改加班信息")]
        [ProducesResponseType(typeof(WorkOvertimeRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "work_overtime_record_no")] string workOverTimeRecordNo, [FromBody] WorkOvertimeRecordSimPutDto dto)
        {
            return this.Ok(this.workOvertimeRecordService.Update(workOverTimeRecordNo, dto));
        }

        #endregion

        #region 获取一条加班信息
        /// <summary>
        /// 获取一条加班信息
        /// </summary>
        /// <param name="workOverTimeRecordNo">加班信息ID</param>
        /// <returns></returns>
        [HttpGet("{work_overtime_record_no}")]
        [ProducesResponseType(typeof(WorkOvertimeRecordDto), 200)]

        public IActionResult Get([FromRoute(Name = "work_overtime_record_no")] string workOverTimeRecordNo)
        {
            return Ok(this.workOvertimeRecordService.Get(workOverTimeRecordNo));
        }

        #endregion

        #region 获取加班信息接口（分页）
        /// <summary>
        /// 获取加班信息列表（分页）
        /// </summary>
        /// <param name="adminName">员工姓名</param>     
        /// <param name="phone">手机号</param>
        /// <param name="adminId">员工编号</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ascending">排序</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">带有分页信息的加班列表。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WorkOvertimeRecordDto>), 200)]
        public IActionResult Query([FromQuery(Name = "admin_name")]string adminName,     
            [FromQuery(Name = "phone")]string phone,
            [FromQuery(Name = "admin_id")] long? adminId,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            int pageIndex = 1,
            int pageSize = 10)
        {
            var list = this.workOvertimeRecordService.List(adminName, phone, adminId, start, end, ascending, pageIndex, pageSize);
            return this.Ok(list);

        }
        #endregion
    }
}
